<%@page import="java.util.ArrayList"%>
<%@page import="com.netistate.pojo.User"%>
<%@page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/default.css" />
		<script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/js/table.js"></script>
	    <script type="text/javascript" src="${pageContext.request.contextPath}/js/trash.js"></script>
	    <script type="text/javascript" src="${pageContext.request.contextPath}/js/md5.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/plugin/msgbox/msgbox.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/jsp/project/project.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/jsp/user/userManager.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/plugin/calendar/Calendar.js"></script>
		<script type="text/javascript">
	   function add(){
	      PigossMsg.show("${pageContext.request.contextPath}/jsp/user/addUser.jsp","添加用户",280,250,"AddUser.saveConfig()");

	   }
	   function edit(id){
	   		AjaxUtil.request({
				url : 'edit_user.action',
				params : {id:id},
				success : function(responseText){
		         PigossMsg.show("${pageContext.request.contextPath}/jsp/user/editUser.jsp?id="+id,"修改用户资料",280,230,"EditUser.editConfig()");
				},
				failure : function(){
					 PigossMsg.alert("编辑失败!");
				}
			});
	   }
	   function editPwd(id){
	   		AjaxUtil.request({
				url : 'edit_user.action',
				params : {id:id},
				success : function(responseText){
	        		PigossMsg.show("${pageContext.request.contextPath}/jsp/user/editPassword.jsp?id="+id,"修改用户密码",290,180,"EditPassword.editPasswordConfig()");
				},
				failure : function(){
					 PigossMsg.alert("编辑失败!");
				}
			});
	   }
	   function editPwdAdmin(id){
	       PigossMsg.show("${pageContext.request.contextPath}/jsp/user/editPassword.jsp?opt=admin&id="+id,"修改用户密码",290,180,"EditPasswordAdmin.editPasswordConfig()");
	   }
	   function del(id,msg){
	        this.msg = msg;
	        //PigossMsg.confirm(this.msg,null,function yesHandler(){EditUser.del(id)},function noHandler(){});
	        PigossMsg.alert("用户不能删除！");
	   }
	</script>
	<style type="text/css">
		.overTd {table-layout:fixed}
		.overTd td{text-overflow:ellipsis;overflow:hidden;white-space:nowrap;padding:0px}
    </style>
	</head>
	<body>
		<form action="findAllUser.action" id="findAllUser" name=""></form>
		<%
			User u = (User)request.getSession().getAttribute("session_user");
			
			List<User> lists = new ArrayList<User>();
			List<User> userlist = (List<User>)request.getAttribute("uList");
			if(userlist == null){
				lists = (List<User>)request.getSession().getAttribute("allUser");
			}else{
				lists = userlist;
			}
		%>
		
		<%if (u.getUsername().equals("admin")) {%>
		<div class="toolbar">
			<a href="#" class='buttonlink txbtip' title='添加用户' onclick="add()">
			<img width='16' height='16' src='${pageContext.request.contextPath}/images/common/plus.png' />添加用户</a>
		</div>
		<%}%>

		<div id="rcon_onepage" style="width: 100%; height: 100%; overflow-y: scroll; border: 1px solid;">
			<table id="dArticleList" width="100%" border="0" cellpadding="0"
				cellspacing="1" class="resizable overTd">
				<thead>
				<tr class="fixHead">
					<td class="td1" style="cursor:pointer" width="10%">用户名</td>
					<td class="td1" style="cursor:pointer" width="10%">真实姓名</td>
					<td class="td1" style="cursor:pointer" width="25%">联系电话</td>
					<td class="td1" style="cursor:pointer" width="25%">电子邮箱</td>
					<%if(u.getUsername().equals("admin")){%>
					    <td class="td1" colspan="3"> 操作</td>
				    <%}else{%>
					   <td class="td1" colspan="2">操作</td>
				    <%}%>
				</tr>
                </thead>
					<%
					for (int i = 0; i < lists.size(); i++) {
						User user = lists.get(i);
						int id = user.getId();
						String name = user.getUsername();
						String realName = user.getRealName();
						String phone = user.getTel();
						String email = user.getEmail();
						String pwd = user.getPassword();
				            %>
				    <tr onMouseOver= "this.bgColor   =   '#cccccc '; "   onMouseOut= "this.bgColor   =   '#FFFFFF'; ">  
					<td title="<%=name%>" align="center" class="td2 txbtip"><%=name%>&nbsp;</td>
					<td title="<%=realName%>" align="center" class="td2 txbtip"><%=realName%>&nbsp;</td>
					<%if (phone == null || phone.equals("")) {%>
					<td align="center" class="td2 txbtip">&nbsp;&nbsp;</td>
					<%} else {%>
					<td title="<%=phone%>" align="center" class="td2 txbtip"><%=phone%>&nbsp;</td>
					 <%}
							if (email == null || email.equals("")) {
						%>
					<td align="center" class="td2 txbtip">&nbsp;&nbsp;</td>
					<%} else {%>
					<td title="<%=email%>" align="center" class="td2 txbtip"><%=email%>&nbsp;</td>
					<%}
						if (u.getUsername().equals("admin")) {
							if (name.equals(u.getUsername())) {
					%>
					<td align="center" class="td2 txbtip">
						<a href="#" class='buttonlink txbtip' title='修改' onclick="edit('<%=id%>')"><img width='16' height='16'
								src='${pageContext.request.contextPath}/images/common/edit.png' /> </a>
					</td>
					<td align="center" class="td2 txbtip">
						<a href="#" class='buttonlink txbtip' title='修改密码' onclick="editPwd('<%=id%>')"><img width='16' height='16'
								src='${pageContext.request.contextPath}/images/common/key.png' /> </a>
					</td>
					<td align="center" class="td2 txbtip">&nbsp;</td>
					<%}	else {%>
					<td align="center" class="td2 txbtip">
						<a href="#" class='buttonlink txbtip' title='修改' onclick="edit('<%=id%>')"><img width='16' height='16'
								src='${pageContext.request.contextPath}/images/common/edit.png' /> </a>
					</td>
					<td align="center" class="td2 txbtip">
						<a href="#" class='buttonlink txbtip' title='修改密码' onclick="editPwd('<%=id%>')"><img width='16' height='16'
								src='${pageContext.request.contextPath}/images/common/key.png' /> </a>
					</td>
					<td align="center" class="td2 txbtip">
						<a href="#" class='buttonlink txbtip' title='删除' onclick="del('<%=id%>','你确定要删除？')"><img width='16'
								height='16' src='${pageContext.request.contextPath}/images/common/delete.png' />
						</a>
					</td>
					<%}
							} else {
								if (name.equals(u.getUsername())) {
					%>
					<td align="center" class="td2 txbtip">
						<a href="#" class='buttonlink txbtip' title='修改' onclick="edit('<%=id%>')"><img width='16' height='16'
								src='${pageContext.request.contextPath}/images/common/edit.png' /> </a>
					</td>
					<td align="center" class="td2 txbtip">
						<a href="#" class='buttonlink txbtip' title='修改密码' onclick="editPwd('<%=id%>')"><img width='16' height='16'
								src='${pageContext.request.contextPath}/images/common/key.png' /> </a>
					</td>
					<%} else {%>
					<td align="center" class="td2 txbtip">&nbsp;</td>
					<td align="center" class="td2 txbtip">&nbsp;</td>
					<%}}}%>
		</table>
		</div>
		<script type="text/javascript" >
		initTableWidget('dArticleList',Array('S','S',"S",'S','S','S','S','S','S','S',false));
		</script>
	</body>
</html>